package com.raymond.thread;

import com.raymond.bean.Message;
import com.raymond.redis.RedisConsumer;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CountDownLatch;

/**
 * 取redis数据
 *
 * @author :  raymond
 * @version :  1.0
 * @date :  2019/7/22
 */
@Slf4j
public class RedisConsumerThread extends Thread {
    private RedisConsumer redisConsumer;

    private CountDownLatch latch;
    @Override
    public void run() {
        boolean flag = true;
        Message message;
        while (flag) {
            message = redisConsumer.getMessage(1, "redis2");
            if (message == null) {
                flag = false;
            }
        }
        log.info("已取完");
        latch.countDown();
    }

    public RedisConsumerThread(RedisConsumer redisConsumer, CountDownLatch latch) {
        this.redisConsumer = redisConsumer;
        this.latch = latch;
    }
}
